#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
#include <fstream>
#include <QDir>
#include <QDebug>

void QComboBoxStaticTest(Ui::Widget* ui, Widget* Pthis) {
    (void)Pthis;

    ui->comboBox->insertItem(0, "");
    ui->comboBox->addItem("麦辣鸡腿堡");
    ui->comboBox->addItem("巨无霸");
    ui->comboBox->addItem("培根蔬萃双层牛堡");

    ui->comboBox_2->addItem("中薯条");
    ui->comboBox_2->addItem("麦乐鸡块");
    ui->comboBox_2->addItem("麦辣鸡翅");

    ui->comboBox_3->addItem("可乐");
    ui->comboBox_3->addItem("雪碧");
}

void QComboBoxDynamicTest(Ui::Widget* ui, Widget* Pthis) {
    (void)Pthis;
    QString workingDir = QDir::currentPath() + "/config.txt";
    qDebug() << workingDir;

    std::ifstream file(workingDir.toStdString());
    if (!file.is_open()) {
        qDebug() << "文件打开失败";
        return;
    }

    //按行来读取文本内容
    //getline 函数完成
    std::string line;
    while (std::getline(file, line)) {
        //取到的每一行内容，设置到下拉框中
        ui->comboBox_4->addItem(QString::fromStdString(line));
    }

    file.close();
}

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    QComboBoxStaticTest(ui, this);
    QComboBoxDynamicTest(ui, this);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{
   qDebug() << ui->comboBox->currentText() << ", " << ui->comboBox_2->currentText() << ", " << ui->comboBox_3->currentText();
}
